package client;

import java.util.Properties;

import nanoxml.XMLElement;
import utils.ITransmittable;

import commands.Commands;

/**
 * The game settings for each table that a player creates.
 */
public class GameSettings implements ITransmittable
{
	public static final String PROPERTY_KEY_DOES_LIMIT_TURN_TIME = "DoesLimitTurnTime";
	public static final String PROPERTY_KEY_TURN_TIME_LIMIT_SECONDS = "TurnTimeSeconds";
	public static final String PROPERTY_KEY_DOES_SHOW_ENEMY_WEAPONS_AFTER_BATTLE = "DoesShowEnemeyWeaponsAfterBattle";
	public static final String PROPERTY_KEY_DOES_ALLOW_VIEWERS_SEE_UNREVEALED_WEAPONS = "DoesAllowUsersSeeUnrevealedWeapons";
	
	public static final boolean  PROPERTY_DEFAULT_VALUE_DOES_LIMIT_TURN_TIME = true;
	public static final String   PROPERTY_DEFAULT_VALUE_TURN_TIME_LIMIT_SECONDS = "15";
	public static final boolean  PROPERTY_DEFAULT_VALUE_DOES_SHOW_ENEMY_WEPAONS_AFTER_BATTLE = true;
	public static final boolean  PROPERTY_DEFAULT_VALUE_DOES_ALLOW_VIEWERS_SEE_UNREVEALED_WEAPONS = true;
	
	private Properties properties = null;
	
	
	public GameSettings()
	{
		properties = new Properties();
	}
	
	public GameSettings(XMLElement message)
	{
		this();
		
		properties.setProperty(PROPERTY_KEY_DOES_LIMIT_TURN_TIME, message.getStringAttribute(PROPERTY_KEY_DOES_LIMIT_TURN_TIME));
		properties.setProperty(PROPERTY_KEY_TURN_TIME_LIMIT_SECONDS, message.getStringAttribute(PROPERTY_KEY_TURN_TIME_LIMIT_SECONDS));
		properties.setProperty(PROPERTY_KEY_DOES_SHOW_ENEMY_WEAPONS_AFTER_BATTLE, message.getStringAttribute(PROPERTY_KEY_DOES_SHOW_ENEMY_WEAPONS_AFTER_BATTLE));
		properties.setProperty(PROPERTY_KEY_DOES_ALLOW_VIEWERS_SEE_UNREVEALED_WEAPONS, message.getStringAttribute(PROPERTY_KEY_DOES_ALLOW_VIEWERS_SEE_UNREVEALED_WEAPONS));
	}


	public String getSetting(String settingName)
	{
		return properties.getProperty(settingName);
	}
	
	public void setSetting(String settingName, String settingValue)
	{
		properties.setProperty(settingName, settingValue);
	}
	
	@Override
	public XMLElement toXML()
	{
		XMLElement xmlMessage = new XMLElement ();
		xmlMessage.setName(Commands.GAME_SETTINGS);
		
		xmlMessage.setAttribute(PROPERTY_KEY_DOES_LIMIT_TURN_TIME , properties.getProperty(PROPERTY_KEY_DOES_LIMIT_TURN_TIME));
		xmlMessage.setAttribute(PROPERTY_KEY_TURN_TIME_LIMIT_SECONDS , properties.getProperty(PROPERTY_KEY_TURN_TIME_LIMIT_SECONDS));
		xmlMessage.setAttribute(PROPERTY_KEY_DOES_SHOW_ENEMY_WEAPONS_AFTER_BATTLE , properties.getProperty(PROPERTY_KEY_DOES_SHOW_ENEMY_WEAPONS_AFTER_BATTLE));
		xmlMessage.setAttribute(PROPERTY_KEY_DOES_ALLOW_VIEWERS_SEE_UNREVEALED_WEAPONS , properties.getProperty(PROPERTY_KEY_DOES_ALLOW_VIEWERS_SEE_UNREVEALED_WEAPONS));
		
		return xmlMessage;
	}
}
